﻿using GrainManage.Entities.Status;
using System;
using System.Collections.Generic;

namespace GrainManage.Server.Business
{
    public class StatusBusiness : BaseBusiness, GrainManage.Interface.IStatus
    {
        //************************************************POST************************************************

        public OutputGetMessage GetMessage(InputGetMessage input)
        {
            var result = new OutputGetMessage();
            try
            {
                var service = ObjectFactory.StatusService;
                result.StatusMessage = service.GetMessage(input.StatusCode);
                if (string.IsNullOrEmpty(result.StatusMessage))
                {
                    SetResponse(StatusCode.NoData, input, result);
                }
                else
                {
                    SetResponse(StatusCode.Success, input, result);
                }
            }
            catch (Exception e)
            {
                SetResponse(StatusCode.Failed, input, result, e);
            }

            return result;
        }

        public OutputSearch Search(InputSearch input)
        {
            var result = new OutputSearch();
            try
            {
                var service = ObjectFactory.StatusService;
                var table = service.Search(input.FilterMessage, input, result);
                result.Statuses = table;
                if (result.Statuses.Count == 0)
                {
                    SetResponse(StatusCode.NoData, input, result);
                }
                else
                {
                    SetResponse(StatusCode.Success, input, result);
                }
            }
            catch (Exception e)
            {
                SetResponse(StatusCode.Failed, input, result, e);
            }

            return result;
        }

        public OutputGetOverView GetOverView(InputGetOverView input)
        {
            var result = new OutputGetOverView { Statuses = new Dictionary<int, string>() };
            try
            {
                var service = ObjectFactory.StatusService;
                var table = service.GetOverView(input, result);
                result.Statuses = table;
                if (result.Statuses.Count == 0)
                {
                    SetResponse(StatusCode.NoData, input, result);
                }
                else
                {
                    SetResponse(StatusCode.Success, input, result);
                }
            }
            catch (Exception e)
            {
                SetResponse(StatusCode.Failed, input, result, e);
            }

            return result;
        }
    }
}
